#!/usr/bin/env groovy

pipeline {
  agent none
  stages {

    stage('Build') {

      parallel {

        stage('px4_sitl_default (OSX)') {
          agent {
            label 'mac'
          }
          environment {
            CCACHE_BASEDIR = "${env.WORKSPACE}"
          }
          steps {
            sh 'export'
            sh 'make distclean'
            sh 'git fetch --tags'
            sh 'ccache -s'
            sh 'make px4_sitl_default'
            sh 'ccache -s'
          }
          post {
            always {
              sh 'make distclean'
            }
          }
        } // stage px4_sitl_default

        stage('px4_fmu-v5_default (OSX)') {
          agent {
            label 'mac'
          }
          environment {
            CCACHE_BASEDIR = "${env.WORKSPACE}"
          }
          steps {
            sh 'export'
            sh 'make distclean'
            sh 'git fetch --tags'
            sh 'ccache -s'
            sh 'make px4_fmu-v5_default'
            sh 'ccache -s'
          }
          post {
            always {
              sh 'make distclean'
            }
          }
        } // stage px4_fmu-v5_default

        stage('sitl tests (OSX)') {
          agent {
            label 'mac'
          }
          environment {
            CCACHE_BASEDIR = "${env.WORKSPACE}"
          }
          steps {
            sh 'export'
            sh 'make distclean'
            sh 'git fetch --tags'
            sh 'ccache -s'
            sh 'make tests'
            sh 'ccache -s'
          }
          post {
            always {
              sh 'make distclean'
            }
          }
        } // stage sitl tests

      } // parallel
    } // stage Build

  } // stages
  environment {
    CCACHE_CPP2 = '1'
    CCACHE_DIR = '/tmp/ccache'
    CI = true
  }
  options {
    buildDiscarder(logRotator(numToKeepStr: '10', artifactDaysToKeepStr: '20'))
    timeout(time: 120, unit: 'MINUTES')
  }
}
